<template>
	<view class="denglbox">
		<view class="sishitext">欢迎登录</view>
		<view class="margin_top7">
			<input class="inputs" type="number" placeholder="请输入账号" v-model="account">
		</view>
		<view class="margin_top">
			<input class="inputs" type="password" placeholder="请输入密码" v-model="password">
		</view>
		<view class="flexbetween margin_top ">
			<view class="ershib" @click="tzwjmm">忘记密码？</view>
			<view class="ershib" @click="tzdxyzmdl">短信验证码登录</view>
		</view>
		<view class="margin_top7 flexleft" @click="xiaoshi">
			<view :class="quan?'yigouxuan margin_right1':'weigouxuan margin_right1'"></view>
			<view class="flexleft">
				<view class="huisetext">阅读并同意</view>
				<view class="huangsetext" @click="yizygy(1)">《用户协议》</view>
				<view class="huisetext">和</view>
				<view class="huangsetext" @click="yizygy(2)">《隐私保护政策》</view>
			</view>
		</view>
		<view class="margin_top bigbtn" @click="thelogin">登录</view>
		<view class="margin_top flexcenter">
			<view class="jiutext">没有账号？</view>
			<view class="huangsetext" @click="tzljzc">立即注册</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				quan: false,
				account: "",
				password: "",
			}
		},
		methods: {
			thelogin() {
				let _this = this
				let mobile = _this.account;
				let password = _this.password
				if (mobile == '') {
					httpRequest.toast('请输入手机号');
					return false;
				}
				if (!mobile.match(/^1\d{10}$/)) {
					httpRequest.toast("请输入有效的手机号码");
					return false;
				}
				if (password == "") {
					httpRequest.toast('请输入密码');
					return false;
				}
				if (!_this.quan) {
					httpRequest.toast('请仔细阅读用户协议并勾选');
					return false;
				}
				httpRequest.request('/api/user/login', 'POST', {
					account: mobile,
					password: password
				}).then(resp => {
					if (resp.code == 1) {
						httpRequest.toast(resp.msg);
						setTimeout(() => {
							let userinfo = resp['data']['userinfo'];
							// 存
							uni.setStorageSync('token', userinfo['token']);
							uni.setStorageSync('user_id', userinfo['user_id']);
							// uni.navigateBack(1)
							uni.reLaunch({
								url: '/pages/homepage/homepage'
							})
						}, 1000)
					}
					if (resp.code == 0) {
						httpRequest.toast(resp.msg);
					}
				})
			},
			// 跳转忘记密码
			tzwjmm() {
				uni.navigateTo({
					url: '/pages/login/wangjmm'
				})
			},
			// 跳转立即注册
			tzljzc() {
				uni.navigateTo({
					url: '/pages/login/lijizhuce'
				})
			},
			// 跳转短信验证码登录
			tzdxyzmdl() {
				uni.navigateTo({
					url: '/pages/login/duanxinyzmdl'
				})
			},
			xiaoshi() {
				this.quan = !this.quan
			},
			// 跳转用户协议，隐私政策，关于我们
			yizygy(i) {
				uni.navigateTo({
					url: '/pages/mypage/guanyuwomen?id=' + i
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.jiutext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.huangsetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FAB536;
	}

	.huisetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.inputs {
		padding-bottom: 30rpx;
		border-bottom: 2rpx solid rgba(153, 153, 153, 0.1);
	}

	.sishitext {
		font-size: 40rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.denglbox {
		padding: 208rpx 30rpx 0;
	}
</style>
